home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / turbovis / tvg103_s.zip / TVGRAPH.PAS < prev    next >
Pascal/Delphi Source File  |  1992-07-29  |  22KB  |  844 lines

  1.  
  2. {$A-,B-,D+,E+,F+,G-,I+,L+,N-,O-,R-,S-,V-,X-}
  3. {$M 16384,0,655360}
  4. {$DEFINE DEMO}
  5. unit TvGraph;
  6.  
  7. (* Include this unit before any other TVision unit and the program will *)
  8. (* Work entirely in graphics mode and look identical ( although slower) *)
  9. (* to the original text display. Using this in conjunction with a       *)
  10. (* companion unit TVGOBJ, will allow you to do graphics using the full  *)
  11. (* capability of TURBO VISION Menus,Dialog boxes etc.                   *)
  12.  
  13. interface
  14.  
  15. uses
  16.   Drivers,Objects,Views;
  17.  
  18. const
  19.   GraphXMax=10000;
  20.   GraphYMax=07500;
  21.   smEGA = $0010;
  22.   smVGA = $0012;
  23.   smGraphAutoDetect=$00FF;   (* Autodetect *)
  24.   wrmOVERWRITE = 0;
  25.   wrmAND = 1;
  26.   wrmOR = 2;
  27.   wrmXOR = 3;
  28.  
  29. var
  30.   GraphMouseLoc:TPoint; (* Graphics location of Mouse *)
  31.  
  32.  
  33. type
  34.  PGRect=^GRect;
  35.  GRect=Trect;
  36.  
  37.  PGPoint=^GPoint;
  38.  GPoint=TPoint;
  39.  
  40. function NextGraphId:byte;
  41. procedure UseGraphId(b:byte);
  42. procedure ReleaseGraphId(b:byte);
  43. procedure TextToGraphics(T:TRect;var G:Grect);
  44. procedure RawDrawLine(X1,Y1,X2,Y2:integer;Color:word);
  45. procedure DrawLine(X1,Y1,X2,Y2:integer;Color:word);
  46. function ISin(X:integer):integer;
  47. function ICos(X:integer):integer;
  48.  
  49. implementation
  50.  
  51. const
  52.   (********************************************************************)
  53.   (*                                                                  *)
  54.   (*    CRITICAL - WARNING LOOK AT THIS CONSTANT - VERSION DEPENDANT  *)
  55.   (*                                                                  *)
  56.   (********************************************************************)
  57.   OfsFromInit=$261-$222;
  58.   (* Offset between where the Views.Tview.Init procedure is and where *)
  59.   (* the code starts for the Checksnow = TRUE code                    *)
  60.   (* This value is absolutely critical and may change between         *)
  61.   (* Turbovision releases  WATCH OUT CRITICAL                         *)
  62.  
  63.   CurrentGraphWindow:byte=1;
  64.   CurrentLineStyle:word=$FFFF;
  65.                         (* Current Line style in 1=line 0=no line       *)
  66.   CurrentLineWriteMode:byte=$00;
  67.                         (* Current Write mode for lines                 *)
  68.   SineTable:array[0..180] of integer=
  69.        (0,9,18,27,36,45,54,63,71,80,89,98,107,116,125,134,143,151,160,169,178,
  70.         187,195,204,213,222,230,239,248,256,265,274,282,291,299,308,316,325,333,
  71.         342,350,359,367,375,384,392,400,408,416,425,433,441,449,457,465,473,481,
  72.         489,496,504,512,520,527,535,543,550,558,565,573,580,587,595,602,609,616,
  73.         623,630,637,644,651,658,665,672,679,685,692,698,705,711,718,724,730,737,
  74.         743,749,755,761,767,773,779,784,790,796,801,807,812,818,823,828,834,839,
  75.         844,849,854,859,864,868,873,878,882,887,891,896,900,904,908,912,916,920,
  76.         924,928,932,935,939,943,946,949,953,956,959,962,965,968,971,974,977,979,
  77.         982,984,987,989,991,994,996,998,1000,1002,1003,1005,1007,1008,1010,1011,
  78.         1013,1014,1015,1016,1017,1018,1019,1020,1021,1022,1022,1023,1023,1023,
  79.         1024,1024,1024,1024);
  80.  
  81.  
  82. type
  83. {$IFDEF DEMO}
  84.   Vector = record X1,Y1,X2,Y2:word; end;
  85. {$ENDIF}
  86.   ABitFont = array[0..255] of array[0..15] of byte;
  87.   (* Store upto 32 line high font *)
  88.   PAbitFont = ^ABitFont;
  89.   (* The pointer to a copy of the currently in use font *)
  90.   PtrRec = record O,S:word; end;  (* used to separate Ofs and Seg     *)
  91. var
  92.   (* All the hardware dependant routines called indirectly *)
  93.   Do_INIT_X:procedure;
  94.   Do_DONE_X:Procedure;
  95.   TVGraphCursorOn_X,
  96.   TVGraphCursorOff_X,
  97.   TVUpdateCursor_X,
  98.   Do_GraphMOV_X,
  99.   NewJmp_GraphMOV_X:pointer;
  100.   Draw_Any_Line_X:procedure (X1,Y1,X2,Y2:word;Color:byte);
  101.   Draw_Horiz_Line_X:procedure (X1,X2,Y:word;Color:byte);
  102.   Draw_Vert_Line_X:procedure (X,Y1,Y2:word;Color:byte);
  103.  
  104.   P1,P2:Pointer;        (* General pointers used for copies             *)
  105.   BytesPerLine:word;    (* Bytes per line in graphics mode              *)
  106.   VideoBufferSeg:word;  (* Video Segment for display                    *)
  107.   GTVEventRoutine:PtrRec;
  108.                         (* Address of TVision mouse event handler       *)
  109.   GTVEventMask:word;    (* Mask as passed by call to handler install    *)
  110.   OldINT33h,OldINT10h:Pointer;
  111.                         (* Old pointers to call for INT 33 and INT 10   *)
  112.   Int33h:Pointer absolute $0000:$00CC;
  113.                         (* INT 33h actual address                       *)
  114.   Int10h:Pointer absolute $0000:$0040;
  115.                         (* INT 10h actual address                       *)
  116.   RomFont:PABitFont absolute $0000:$010C;
  117.                         (* Address of current FONT                      *)
  118.   ColorList:word;       (* Pointer to List of color masks in EGA memory *)
  119.   Count:word;           (* Counts down the number of char's in GRAPHMOV *)
  120.   DestOfs:word;         (* Destination in EGA of the current mask       *)
  121.   TextSource:PtrRec;    (* Source for next Ch/Attr pair                 *)
  122.   TextDest:word;        (* Normal destination for text 0..screen size   *)
  123.   SaveJump:word;        (* Save jump location for GraphMov              *)
  124.   TvGraphLoc,TvGraphCursor:word;
  125.                         (* Store current text x,y and top/bottom cursor *)
  126.   TvViziFlag:byte;      (* Toggles ON=FF and OFF=00 for cursor          *)
  127.   FontTable:ABitFont;   (* In Memory font table                         *)
  128.   PtrFontTable:PABitFont;(* Pointer to In Memory font table             *)
  129.   GraphWriteAvail:array[0..4095] of byte;
  130.   (* one byte for each text position on the screen, 0=text screen and   *)
  131.   (* a number 1-254 representing distinct graphics windows and 255      *)
  132.   (* represents the mouse cursor positions                              *)
  133.   GraphIdSet:set of byte;
  134.   CharWidth,CharHeight:byte;
  135.                         (* Width and Height in text mode                *)
  136.   GraphWidth,GraphHeight:word;
  137.                         (* Width and height in graphics                 *)
  138. {$IFDEF DEMO}
  139.   DWString:array[1..35] of word; (* Used for text writing *)
  140.  
  141. const
  142.   TVGraphAd:array[1..29] of Vector=
  143.   ((X1:220;Y1:125;X2:240;Y2:125), (*T2*)
  144.    (X1:230;Y1:125;X2:230;Y2:150),
  145.    (X1:245;Y1:125;X2:255;Y2:150), (*V2*)
  146.    (X1:255;Y1:150;X2:265;Y2:125),
  147.    (X1:290;Y1:125;X2:280;Y2:125), (*G7*)
  148.    (X1:280;Y1:125;X2:270;Y2:130),
  149.    (X1:270;Y1:130;X2:270;Y2:145),
  150.    (X1:270;Y1:145;X2:280;Y2:150),
  151.    (X1:280;Y1:150;X2:290;Y2:150),
  152.    (X1:290;Y1:150;X2:290;Y2:140),
  153.    (X1:290;Y1:140;X2:280;Y2:140),
  154.    (X1:295;Y1:150;X2:295;Y2:125), (*R6*)
  155.    (X1:295;Y1:125;X2:305;Y2:125),
  156.    (X1:305;Y1:125;X2:315;Y2:130),
  157.    (X1:315;Y1:130;X2:315;Y2:135),
  158.    (X1:315;Y1:135;X2:295;Y2:140),
  159.    (X1:305;Y1:140;X2:315;Y2:150),
  160.    (X1:320;Y1:150;X2:320;Y2:135), (*A5*)
  161.    (X1:320;Y1:135;X2:330;Y2:125),
  162.    (X1:330;Y1:125;X2:340;Y2:135),
  163.    (X1:340;Y1:135;X2:340;Y2:150),
  164.    (X1:320;Y1:140;X2:340;Y2:140),
  165.    (X1:345;Y1:150;X2:345;Y2:125), (*P4*)
  166.    (X1:345;Y1:125;X2:365;Y2:125),
  167.    (X1:365;Y1:125;X2:365;Y2:140),
  168.    (X1:365;Y1:140;X2:345;Y2:140),
  169.    (X1:370;Y1:125;X2:370;Y2:150), (*H3*)
  170.    (X1:390;Y1:125;X2:390;Y2:150),
  171.    (X1:370;Y1:137;X2:390;Y2:137));
  172.   AdvertText:array[1..9] of string[35]=
  173.   ('      Graphics in TURBOVISION      ',
  174.    '         Copyright 1991            ',
  175.    'C.L.Burke of MindWare QLD Australia',
  176.    'R.A.Morris of KHIRON QLD Australia ',
  177.    '         The Wizards of Oz         ',
  178.    '          AND COMING SOON          ',
  179.    '   GWHIZ graphics objects in the   ',
  180.    '      spirit of TurboVision        ',
  181.    '    PRESS ANY KEY TO CONTINUE      ');
  182. {$ENDIF}
  183.  
  184. procedure DisableInterrupts; inline($FA);
  185. procedure EnableInterrupts; inline($FB);
  186.  
  187. procedure MouseCursorOff;assembler;
  188. asm
  189.  mov ax,0002h
  190.  cli
  191.  pushf
  192.  call [OldInt33h]
  193.  sti
  194. end;
  195.  
  196. procedure MouseCursorOn;assembler;
  197. asm
  198.  mov ax,0001h
  199.  cli
  200.  pushf
  201.  call [OldInt33h]
  202.  sti
  203. end;
  204.  
  205. {$I TVGRAPH.IN0}        (* Display Identify routines *)
  206. {$I TVGRAPH.IN1}        (* Display Specific routines *)
  207.  
  208.  
  209. {$IFDEF DEMO}
  210.  
  211. procedure RawWriteString(X,Y:Word;S:String);
  212. const
  213.  NormTextColor=$1A00;
  214. var
  215.  ScrLoc:word;
  216.  Cnt:word;
  217. begin
  218.  ScrLoc:=Y*160+X*2;
  219.  for Cnt:=1 to 35 do
  220.    DWString[Cnt]:=No